import { GSprite } from "../../../../com/mui/controls/GSprite";
import { ObjCreate } from "../common/ObjCreate";
import { ImagesConst } from "../../resource/ImagesConst";
import { BaseItem } from "../common/BaseItem";
import { LoaderHelp } from "../../../common/display/LoaderHelp";
import { ResFileConst } from "../../resource/ResFileConst";
import { GlobalClass } from "../../../../com/mui/core/GlobalClass";
import { SNewLoginBackRewardInfo } from "../../../../Message/Game/SNewLoginBackRewardInfo";
import { ItemData } from "../../resource/info/ItemData";
import { MsgManager } from "../../manager/MsgManager";
import { Language } from "../../../../extend/language/Language";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { TweenLite } from "../../../../com/greensock/TweenLite";
import { FlyToNavbarTool } from "../award/FlyToNavbarTool";
type int = number;
//class DayRewardItem
    
    export  class DayRewardItem extends GSprite
    {
        constructor()
        {
            super();
            this.init();
            addEventListener(flash.events.MouseEvent.CLICK, this.onDayRewardItemClickHandler);
            return;
        }

        /* internal  */init(): void
        {
            this._propBg = ObjCreate.createBitmap(ImagesConst.PropBg, 0, 0, this);
            this._baseItem = new BaseItem();
            this._baseItem.move(4, 5);
            this._baseItem.setSize(60, 60);
            addChild(this._baseItem);
            this._iconBmp = ObjCreate.createBitmap(null, 4, 5, this);
            LoaderHelp.addResCallBack(ResFileConst.LoginGiveBack, this.onResLoaded);
            return;
        }

        /* internal  */onResLoaded(): void
        {
            if (this._iconBmp) 
            {
                this._iconBmp.bitmapData = GlobalClass.getBitmapData(ImagesConst.GiveBackBox);
            }
            return;
        }

        public resetItem(): void
        {
            this._rewardInfo = null;
            this._baseItem.itemData = null;
            if (this._iconBmp == null) 
            {
                this._iconBmp = ObjCreate.createBitmap(null, 4, 5, this);
            }
            this._iconBmp.visible = true;
            LoaderHelp.addResCallBack(ResFileConst.LoginGiveBack, this.onResLoaded);
            return;
        }

        public setIndex(arg1: int): void
        {
            this._index = arg1;
            return;
        }

        public updateItem(arg1: SNewLoginBackRewardInfo): void
        {
            this._rewardInfo = arg1;
            if (!(this._rewardInfo.pos == 0) && this._iconBmp) 
            {
                if (this._isClick) 
                {
                    this.playerFlash();
                    this._isClick = false;
                }
                else 
                {
                    this._iconBmp.visible = false;
                }
            }
            if (this._rewardInfo.itemCode != 0) 
            {
                this._baseItem.itemData = new ItemData(this._rewardInfo.itemCode);
            }
            return;
        }

        /* internal  */onDayRewardItemClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (this._rewardInfo && !(this._rewardInfo.itemCode == 0)) 
            {
                MsgManager.showRollTipsMsg(Language.getString(36536));
            }
            else 
            {
                this._isClick = true;
                Dispatcher.dispatchEvent(new DataEvent(EventName.LoginBackLuckyDrawReward, this._index + 1));
            }
            return;
        }

        /* internal  */playerFlash(): void
        {
            if (this._iconBmp) 
            {
                TweenLite.to(this._iconBmp, 0.5, {"rotation": 180, "x": this.width / 2, "y": this.height / 2, "scaleX": 0, "scaleY": 0, "scaleZ": 0, "onComplete": this.onCompleteHandler});
            }
            return;
        }

        /* internal  */onCompleteHandler(): void
        {
            this._iconBmp.visible = false;
            removeChild(this._iconBmp);
            this._iconBmp = null;
            if (this._baseItem.bitmapdata) 
            {
                FlyToNavbarTool.flyToBackPack(this._baseItem.bitmapdata, localToGlobal(new Object /* flash.geom.Point */(this._baseItem.x, this._baseItem.y)));
            }
            return;
        }

        /* internal */ /* var */_propBg: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_baseItem: BaseItem;

        /* internal */ /* var */_iconBmp: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_rewardInfo: SNewLoginBackRewardInfo;

        /* internal */ /* var */_index: int;

        /* internal */ /* var */_isClick: Boolean=false;
    }
